﻿using System;

using Cookbook.Services.Core.Commands;
using Cookbook.Services.Core.Handlers;
using Cookbook.Services.Core.Persistency;

using Cooking.Services.Specs.Builders;

using FluentAssertions;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Cooking.Services.Specs.Handlers
{
    [TestClass]
    public class AttributeMappedCommandHandlerSpecs
    {
        [TestMethod]
        public void When_executing_command_with_valid_mapping_it_should_execte_the_configured_method()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var recipe = new RecipeBuilder()
                .WithRating(2)
                .Build();

            var mapper = new InMemoryDataMapper(recipe);
            Func<CookbookUnitOfWork> factory = () => new CookbookUnitOfWork(mapper);

            var handler = new AttributeMappedCommandHandler(factory);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            handler.Handle(new RateRecipeCommand
            {
                Id = recipe.Id,
                Version = recipe.Version,
                Rating = 5
            });

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            recipe.Rating.Should().Be(5);
        }
    }
}